package com.xmy.solution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xmy.solution.domain.dto.homepagesolution.HomepageSolutionDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xmy.common.annotation.Log;
import com.xmy.common.core.controller.BaseController;
import com.xmy.common.core.domain.AjaxResult;
import com.xmy.common.enums.BusinessType;
import com.xmy.solution.domain.HomepageSolution;
import com.xmy.solution.service.IHomepageSolutionService;
import com.xmy.common.utils.poi.ExcelUtil;
import com.xmy.common.core.page.TableDataInfo;

/**
 * 首页方案Controller
 * 
 * @author 夏明毅
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/solution/homepageSolution")
public class HomepageSolutionController extends BaseController
{
    @Autowired
    private IHomepageSolutionService homepageSolutionService;

    /**
     * 查询首页方案列表
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomepageSolution homepageSolution)
    {
        startPage();
        List<HomepageSolution> list = homepageSolutionService.selectHomepageSolutionList(homepageSolution);
        return getDataTable(list);
    }

    /**
     * 导出首页方案列表
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:export')")
    @Log(title = "首页方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomepageSolution homepageSolution)
    {
        List<HomepageSolution> list = homepageSolutionService.selectHomepageSolutionList(homepageSolution);
        ExcelUtil<HomepageSolution> util = new ExcelUtil<HomepageSolution>(HomepageSolution.class);
        util.exportExcel(response, list, "首页方案数据");
    }

    /**
     * 获取首页方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:query')")
    @GetMapping(value = "/{solutionId}")
    public AjaxResult getInfo(@PathVariable("solutionId") Long solutionId)
    {
        return success(homepageSolutionService.selectHomepageSolutionBySolutionId(solutionId));
    }

    /**
     * 新增首页方案
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:add')")
    @Log(title = "首页方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomepageSolution homepageSolution)
    {
        return toAjax(homepageSolutionService.insertHomepageSolution(homepageSolution));
    }

    /**
     * 修改首页方案
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:edit')")
    @Log(title = "首页方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomepageSolution homepageSolution)
    {
        return toAjax(homepageSolutionService.updateHomepageSolution(homepageSolution));
    }

    /**
     * 删除首页方案
     */
    @PreAuthorize("@ss.hasPermi('solution:homepageSolution:remove')")
    @Log(title = "首页方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{solutionIds}")
    public AjaxResult remove(@PathVariable Long[] solutionIds)
    {
        return toAjax(homepageSolutionService.deleteHomepageSolutionBySolutionIds(solutionIds));
    }
}
